<?php 
require './top_sdk/TopSdk.php';
echo'<pre>';
print_r ($_GET);
echo'</pre>';
echo $_SERVER['HTTP_REFERER'];echo'<br/>allthis:';
print_r(base64_decode($_GET['top_parameters']));
echo'<br/>';
$arr = $_GET;
unset($arr['top_sign']);
unset($arr['agreement']);
unset($arr['agreementsign']);
unset($arr['x']);
unset($arr['y']);
unset($arr['callback']);
echo'<pre>';
print_r($arr);
echo'</pre>';
//$arr['top_parameters']=base64_decode($arr['top_parameters']);
echo'<br/>';
echo base64_encode(generateSign($arr));
echo'<br/>';

$top_appkey='12198772';
$top_parameters=$_GET['top_parameters'];
$top_session=$_GET['top_session'];
$app_secret = 'sandboxa39dd41f8b7eba4be35728557';
$sign=base64_encode(md5($top_appkey.$top_parameters.$top_session.$app_secret,true));
echo $sign;
	 function generateSign($params){
		ksort($params);

		$stringToBeSigned = '';
		foreach ($params as $k => $v)
		{
			if("@" != substr($v, 0, 1))
			{
				$stringToBeSigned .= "$v";
			}
		}
		unset($k, $v);
		$stringToBeSigned .= 'sandboxa39dd41f8b7eba4be35728557';
	return md5($stringToBeSigned,true);
	}



echo"<br /><br /><br /><br /><br />";
echo getIP();

function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }
    return $realip;
}
?>